﻿using Sidvall.IO;
using System.Threading.Tasks;

namespace Sidvall.Devices
{
    public class CameraManager
    {
        #region Public Members

        public Sidvall.Devices.ICamera Camera { get; set; }

        #region CaptureFileAsync

        public async Task<IStorageFile> CaptureFileAsync(CameraSettings settings)
        {
            if (this.Camera != null)
                return await this.Camera.CaptureFileAsync(settings).ConfigureAwait(false);
            return null;
        }

        #endregion
        #region CapturePhotoAsync

        public async Task<IStorageFile> CapturePhotoAsync(bool allowCropping, PhotoFormat format, PhotoResolution maxResolution)
        {
            var settings = new PhotoSettings()
            {
                AllowCropping = allowCropping,
                Format = format,
                MaxResolution = maxResolution,
            };
            return await CapturePhotoAsync(settings).ConfigureAwait(false);
        }
        public async Task<IStorageFile> CapturePhotoAsync(PhotoSettings settings)
        {
            var cameraSettings = new CameraSettings()
            {
                CaptureMode = CaptureMode.Photo,
                PhotoSettings = settings,
            };
            return await CaptureFileAsync(cameraSettings).ConfigureAwait(false);
        }

        #endregion
        #region CapturePhotoOrVideoAsync

        public async Task<IStorageFile> CapturePhotoOrVideoAsync(PhotoSettings photoSettings, VideoSettings videoSettings)
        {
            var cameraSettings = new CameraSettings()
            {
                CaptureMode = CaptureMode.PhotoOrVideo,
                PhotoSettings = photoSettings,
                VideoSettings = videoSettings,
            };
            return await CaptureFileAsync(cameraSettings).ConfigureAwait(false);
        }

        #endregion
        #region CaptureVideoAsync

        public async Task<IStorageFile> CaptureVideoAsync(bool allowTrimming, VideoFormat format, VideoResolution maxResolution, float maxDurationInSeconds)
        {
            var settings = new VideoSettings()
            {
                AllowTrimming = allowTrimming,
                Format = format,
                MaxResolution = maxResolution,
                MaxDurationInSeconds = maxDurationInSeconds,
            };
            return await CaptureVideoAsync(settings).ConfigureAwait(false);
        }
        public async Task<IStorageFile> CaptureVideoAsync(VideoSettings settings)
        {
            var cameraSettings = new CameraSettings()
            {
                CaptureMode = CaptureMode.Video,
                VideoSettings = settings,
            };
            return await CaptureFileAsync(cameraSettings).ConfigureAwait(false);
        }

        #endregion
        #region ToString

        public override string ToString()
        {
            return "CameraManager - Sidvall.Devices.ICamera";
        }

        #endregion

        #endregion
        #region Constructors

        public CameraManager(Sidvall.Devices.ICamera camera)
        {
            this.Camera = camera;
        }

        #endregion
    }
}
